package io.framework.modules.station.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.framework.common.constant.Constant;
import io.framework.common.page.PageData;
import io.framework.common.service.impl.CrudServiceImpl;
import io.framework.common.utils.ConvertUtils;
import io.framework.modules.air.dto.AirDTO;
import io.framework.modules.air.entity.AirEntity;
import io.framework.modules.station.dao.StationDao;
import io.framework.modules.station.dto.StationDTO;
import io.framework.modules.station.entity.StationEntity;
import io.framework.modules.station.service.StationService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author Gujq email
 * @since 1.0.0 2020-05-20
 */
@Service
public class StationServiceImpl extends CrudServiceImpl<StationDao, StationEntity, StationDTO> implements StationService {

    @Override
    public QueryWrapper<StationEntity> getWrapper(Map<String, Object> params) {
        String id = (String) params.get("id");

        QueryWrapper<StationEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotBlank(id), "id", id);

        return wrapper;
    }

    @Override
    public PageData<StationDTO> pages(Map<String, Object> params) {
        IPage<StationEntity> pages = getPage(params, Constant.CREATE_DATE, false);

        List<StationEntity> list = baseDao.getList(params);

        return getPageData(list, pages.getTotal(), StationDTO.class);
    }

    @Override
    public List<StationDTO> getStationInfoByParams(Map<String, Object> params) {

        List<StationEntity> list = baseDao.getStationInfoByParams(params);

        return ConvertUtils.sourceToTarget(list, StationDTO.class);
    }

    @Override
    public List<StationEntity> getListByCodes(List<String> codes) {
        return baseDao.selectList(new QueryWrapper<StationEntity>().in("code", codes));
    }
}
